package lab03.Test05;

import java.io.*;
import java.util.Scanner;

/**
 * Created by Aguest on 2017/12/8.
 */
public class Test {
        public static void main(String[] args) {
            String path = "E://java.txt";
            String path1 = "E://test.txt";
            BufferedWriter writer=null;
            BufferedWriter writer1=null;
            BufferedReader reader=null;
            try {
                writer = new BufferedWriter(new FileWriter(path));
                writer.write("Hello");
                reader = new BufferedReader(new FileReader(path));
                writer1 = new BufferedWriter(new FileWriter(path1));
                String line;
                String str=null;
                while ((line=reader.readLine())!=null)
                {
                    for(int i=0;i<line.length();i++){
                        char ch=line.charAt(i);
                        if(Character.isLetter(ch)){
                            if(Character.isUpperCase(ch)){
                                if(ch-'A'+1>25){
                                    ch=(char) (('A'+(ch-'A'+1)%26)+26);
                                }else{
                                    ch=(char) (ch+27);
                                }
                            }
                            if(Character.isLowerCase(ch)){
                                if(ch-'a'+1>25){
                                    ch=(char) ('a'+(ch-'a'+1)%26);
                                }else{
                                    ch=(char) (ch+1);
                                }
                            }
                        }
                        str=str+ch;
                    }
                    writer1.write(str);
                    writer1.newLine();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();}catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    writer.close();
                    writer1.close();
                    reader.close();

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("文件加密完毕！");
        }
    }
